#ifndef WORD_FILTER_HPP
#define WORD_FILTER_HPP

#include <set>
#include <string>
#include "file_reader.h++"

class WordFilter {
	static std::set<std::string> badwordz;
public:
	template <typename Caller>
	class Proxy {
		Caller& caller;
	public:
		Proxy(Caller& _caller)  : caller(_caller) { }
		void found_word(UnserializedDocument& doc, Word& word) {
			bool discarded = false;
			if (!word.category.empty()) {
				// if we have a category, then we can filter
				// those that we don't want. (for exemple : 
                // punctuation, determinants, proposition...)
				
				if (word.category == "SENT")
					discarded = true;
				std::string first3 = word.category.substr(0, 3);
				if (first3 == "PRO" || first3 == "DET"
					|| first3 == "PUN")
					discarded = true;
			} else if (word.full_word.length() <= 3)
				// but if we don't have a category, the best
				// guess we can do is filter the small words.
				// that might not be a good idea, especially
				// for acronyms like 'STL', 'PS' or 'EDF'
				discarded = true;
				
			std::transform(word.full_word.begin(),
				word.full_word.end(),
				word.full_word.begin(),
				tolower);
			
			std::transform(word.lemma.begin(),
				word.lemma.end(),
				word.lemma.begin(),
				tolower);

			if (badwordz.find(word.lemma) != badwordz.end())
				discarded = true;
			if (!discarded)
				caller.found_word(doc, word);
			else
				caller.ignoring_word(word);
		}
	};

	template <typename Caller>
	static Proxy<Caller> get_for(Caller& caller) {
		return Proxy<Caller>(caller);
	}
};

#endif
